package com.ruoyi.basebill.controller.billIssue;

import com.ruoyi.basebill.service.billIssue.*;
import com.ruoyi.basebill.service.exception.DataNullException;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("单据下发接口")
@RestController
@RequestMapping("/basebill/billIssue")
public class BillIssueController {

    @Autowired
    public ISbftService sbftService;

    @Autowired
    public ISbjrService sbjrService;

    @Autowired
    public ISbjtService sbjtService;

    @Autowired
    public IGjjftService gjjftService;

    @Autowired
    public IGjjjrService gjjjrService;

    @Autowired
    public IGjjjtService gjjjtService;

    @Autowired
    public INzjchService nzjchService;

    @Autowired
    public INzjffService nzjffService;

    @Autowired
    public INzjftService nzjftService;

    @Autowired
    public IPushGzclService pushGzclService;

    @ApiOperation("单据下发薪酬总表-工资发放社保类")
    @Log(title = "薪酬总表-工资发放下发社保类",businessType = BusinessType.INTERFACE_GZFF)
    @PostMapping("/xczbGzffSb/{ids}")
    public AjaxResult billIssue(@PathVariable Long[] ids){
        StringBuffer stringBuffer = new StringBuffer();
        String s = null;
        for (Long id : ids) {
        //下发社保分摊
        int i1 = sbftService.billIssue(id);
        if (i1 == 1){
            stringBuffer.append("<br/>"+ "单据"+ id + " 下发【社保分摊】单据下发成功！");
        }else {
            stringBuffer.append("<br/>"+ "单据"+ id + " 下发【社保分摊】单据下发失败！");

        }
        //下发社保缴纳
        int i2 = sbjrService.billIssue(id,stringBuffer);
        if (i2 == 1){
            stringBuffer.append("<br/>"+ "单据"+ id + " 下发【社保缴纳】单据下发成功！");
        }else {
            stringBuffer.append("<br/>"+ "单据"+ id + " 下发【社保缴纳】单据下发失败！");

        }
        //下发社保计提
        int i3 = sbjtService.billIssue(id);
        if (i3 == 1){
            stringBuffer.append("<br/>"+ "单据"+ id + " 下发【社保计提】单据下发成功！");
        }else {
            stringBuffer.append("<br/>"+ "单据"+ id + " 下发【社保计提】单据下发失败！");

        }
        stringBuffer.insert(0,"单据下发情况如下：");
        s = stringBuffer.toString();
        }
        return AjaxResult.success(s);
    }

    @ApiOperation("单据下发薪酬总表-工资发放公积金类")
    @Log(title = "薪酬总表-工资发放下发公积金类",businessType = BusinessType.INTERFACE_GZFF)
    @PostMapping("/xczbGzffGjj/{ids}")
    public AjaxResult billIssueGjj(@PathVariable Long[] ids){
        StringBuffer stringBuffer = new StringBuffer();
        String s = null;
        for (Long id : ids) {
            //下发社保分摊
            int i1 = gjjftService.billIssue(id);
            if (i1 == 1){
                stringBuffer.append("<br/>" + "公积金分摊单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "公积金分摊单据下发失败！");

            }
            int i2 = gjjjrService.billIssue(id);
            if (i2 == 1){
                stringBuffer.append("<br/>" + "公积金缴纳单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "公积金缴纳单据下发失败！");

            }
            int i3 = gjjjtService.billIssue(id);
            if (i3 == 1){
                stringBuffer.append("<br/>" + "公积金计提单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "公积金计提单据下发失败！");

            }
            stringBuffer.insert(0,"单据下发情况如下：");
            s = stringBuffer.toString();
        }
        return AjaxResult.success(s);
    }

    @ApiOperation("单据下发薪酬总表-工资发放年终奖类")
    @Log(title = "薪酬总表-工资发放下发年终奖类",businessType = BusinessType.INTERFACE_GZFF)
    @PostMapping("/xczbGzffNzj/{ids}")
    public AjaxResult billIssueNzj(@PathVariable Long[] ids){
        StringBuffer stringBuffer = new StringBuffer();
        StringBuffer stringBuffer1 = new StringBuffer();
        String s = null;
        for (Long id : ids) {
            //下发年终奖冲回
            int i1 = nzjchService.billIssue(id,stringBuffer1);
            if (i1 == 1){
                stringBuffer.append("<br/>" + "年终奖冲回单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "年终奖冲回单据下发失败！");

            }
            int i2 = nzjffService.billIssue(id,stringBuffer1);
            if (i2 == 1){
                stringBuffer.append("<br/>" + "年终奖发放单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "年终奖发放单据下发失败！");

            }
            int i3 = nzjftService.billIssue(id,stringBuffer1);
            if (i3 == 1){
                stringBuffer.append("<br/>" + "年终奖分摊单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "年终奖分摊单据下发失败！");

            }
            stringBuffer.insert(0,"单据下发情况如下：");
            s = stringBuffer.toString();
        }
        return AjaxResult.success(s);
    }

    @ApiOperation("单据下发薪酬总表-工资发放工资类")
    @Log(title = "薪酬总表-工资发放下发工资类",businessType = BusinessType.INTERFACE_GZFF)
    @PostMapping("/xczbGzffGz/{ids}")
    public AjaxResult billIssueGz(@PathVariable Long[] ids) throws DataNullException {
        StringBuffer stringBuffer = new StringBuffer();
        StringBuffer stringBuffer1 = new StringBuffer();
        String s = null;
        for (Long id : ids) {
            //下发工资计提
            int i1 = pushGzclService.pushGzjt(id,stringBuffer1);
            if (i1 == 1){
                stringBuffer.append("<br/>" + "工资计提单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "工资计提单据下发失败！");

            }
            int i2 = pushGzclService.pushGzff(id,stringBuffer1);
            if (i2 == 1){
                stringBuffer.append("<br/>" + "工资发放单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "工资发放单据下发失败！");

            }
            int i3 = pushGzclService.pushGzft(id,stringBuffer1);
            if (i3 == 1){
                stringBuffer.append("<br/>" + "工资分摊单据下发成功！");
            }else {
                stringBuffer.append("<br/>" + "工资分摊单据下发失败！");

            }
            stringBuffer.insert(0,"单据下发情况如下：");
            s = stringBuffer.toString();
        }
        return AjaxResult.success(s);
    }

}
